import requests
from gis空间包含统计.mysqlDB import *


def compare():
    connection = getConnect()
    cursor = connection.cursor()
    query_sql_detail = '''
    select phy_layer_id, phy_layer_name, phy_layer_tname from tc_phy_layer
    '''
    cursor.execute(query_sql_detail)
    all_rec = cursor.fetchall()
    idNameDic = getSeverTables()
    table_names = []
    for rec in all_rec:
        phy_layer_id, phy_layer_name, phy_layer_tname = rec
        if(phy_layer_name in idNameDic and idNameDic.get(phy_layer_name) != phy_layer_tname):
            table_names.append(phy_layer_name)
    print(len(table_names))
    print(table_names)




def getSeverTables():
    url = "http://39.107.248.252:9081/egovagisserver/data/services/3/layers"
    response = requests.request("GET", url)
    tables = response.json().get("data")
    idNameDic = {}
    for table in tables:
        idNameDic[table.get("name")] = table.get("geoName")
    return idNameDic

if __name__ == '__main__':
    compare()